package cn.fr.config;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RestHighLevelClientConfig  {
    @Value("${es.ip}")
    private String esIp;
    @Value("${es.port}")
    private String esPort;
    @Bean
    public RestHighLevelClient elasticsearchClient() {

        // 初始化Elasticsearch客户端
        RestClientBuilder builder = RestClient.builder(new HttpHost(esIp, Integer.parseInt(esPort), "http"));
        RestHighLevelClient client = new RestHighLevelClient(builder);
        return client;
    }
}
